//angular.module('User', ['ngResource']).
//factory('UserResource', function($resource){
//    return $resource('/api/v1/user/:type/?', {type:'@type'}, {
//        query: {method:'GET',isArray:true}
//    });
//}).factory('IndexMsg', function($resource){
//    return $resource('/api/v1/user/index_msg/');
//});



App.factory('rest', function ($http) {
    return {
        get: function (resource, _id) {
            var promise = $http.get('/api/v1/' + resource + '/' + _id + '/').then(function (response) {
                return response.data;
            });
            return promise;
        },
        query: function (resource, params) {
            params = (typeof params) !== 'undefined' ? params : {};
            var promise = $http({ url: '/api/v1/' + resource + '/', method: "GET", params: params})
                .then(function (response) {
                return response.data;
            });
            return promise;
        },
        remove: function (resource, _id) {
            var promise = $http({ url: '/api/v1/' + resource + '/' + _id + '/', method: "DELETE"})
                .then(function (response) {
                return response.data;
            });
            return promise;
        },
        update: function (resource, _id, data) {
            var promise = $http({ url: '/api/v1/' + resource + '/' + _id + '/' , method: "PATCH", data: data})
                .then(function (response) {
                return response.data;
            });
            return promise;
        },
        save: function (resource, data) {
            var promise = $http({ url: '/api/v1/' + resource + '/', method: "POST", data: data})
                .then(function (response) {
                return response.data;
            });
            return promise;
        }
    };
});



